	// verilator_coverage annotation
	module matrix_regs(
 020001	input wire clk,
%000001	input wire rst,
	
%000003	input w_m_en,
 000013	input r_m_en,
	// w: ld.tile mov.tile; r: st.tile mov.tile rd;
 000037	input wire [1:0] w_m_index,
 006612	input wire [1:0] r_m_index,
	
 000486	input wire [31:0] w_m_data,
	
 000276	output wire [31:0] r_m_data,
	
%000003	input wire w_matrix_mopa_en,
	//mopa 
%000423	input wire [31:0] w_matrix_mopa [3:0],
%000233	output wire [31:0] r_matrix_mopa [3:0],
	// ex-mem test 6
%000003	input wire me_matrix_mopa_en,
%000406	input wire[31:0] me_matrix_mopa_o[3:0]
	
	);
	
%000261	reg [31:0] M [3:0]; //matrix regs
	always @(posedge clk)begin
 000100	if (!rst) begin
	M[0] <= 32'h55555555;
	M[1] <= 32'haaaaaaaa;
	M[2] <= 32'h33333333;
	M[3] <= 32'hcccccccc;
	end
%000004	else if (w_m_en) begin
	M[w_m_index] <= w_m_data;
	end
%000001	else if(w_matrix_mopa_en)begin
	M[0] <= w_matrix_mopa[0];
	M[1] <= w_matrix_mopa[1];
	M[2] <= w_matrix_mopa[2];
	M[3] <= w_matrix_mopa[3];
	end
	end
	
	// if read and write use same time, forward;
	assign r_m_data = (r_m_en && w_matrix_mopa_en && r_m_index == 2'b00) ? w_matrix_mopa[0] :
			(r_m_en && w_matrix_mopa_en && r_m_index == 2'b01) ? w_matrix_mopa[1] :
			(r_m_en && w_matrix_mopa_en && r_m_index == 2'b10) ? w_matrix_mopa[2] :
			(r_m_en && w_matrix_mopa_en && r_m_index == 2'b11) ? w_matrix_mopa[3] :
	
	                (r_m_en && me_matrix_mopa_en && r_m_index == 2'b00) ? me_matrix_mopa_o[0] :
	                (r_m_en && me_matrix_mopa_en && r_m_index == 2'b01) ? me_matrix_mopa_o[1] :
	                (r_m_en && me_matrix_mopa_en && r_m_index == 2'b10) ? me_matrix_mopa_o[2] :
	                (r_m_en && me_matrix_mopa_en && r_m_index == 2'b11) ? me_matrix_mopa_o[3] :
	
			(r_m_en && w_m_index == r_m_index && w_m_en) ? w_m_data : 
			(r_m_en) ? M[r_m_index] : 32'h00000000;
	
	//test6 mov.tile and mopa chongtu
	assign r_matrix_mopa[0] = (r_m_en && w_m_en && w_m_index == 2'b00)? w_m_data: M[0];
	assign r_matrix_mopa[1] = M[1];
	assign r_matrix_mopa[2] = M[2];
	assign r_matrix_mopa[3] = M[3];
	
	
	endmodule
	
